﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using ZLDC.Common.BaseUser;

namespace ZLDC.Topo.BLL
{
    /// <summary>
    /// 取得部门数据表(主要用于生成树菜单)
    /// </summary>
    public class Dept
    {
        private static string sKey = "zldclpgl-DeptAll";
        /// <summary>
        /// 取得所有部门数据

        /// </summary>
        /// <returns></returns>
        public static DataSet GetDeptData()
        {
            DataSet ds;
            if (System.Web.HttpContext.Current.Cache[sKey] != null)
            {
                ds = (DataSet)System.Web.HttpContext.Current.Cache[sKey];
            }
            else
            {
                string sSql = "select id,name,grade,parent_id from t_s_alldept where dltflg = 0 and id not in (" + System.Configuration.ConfigurationSettings.AppSettings["OutsideDeptId"] + ") ";
                DataBaseAll db = new DataBaseAll("ZLDCHR");
                ds = db.SelectDataBaseAll(sSql);
                System.Web.HttpContext.Current.Cache.Insert(sKey, ds, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero);
            }
            return ds;
        }

        /// <summary>
        /// 清理部门缓存
        /// </summary>
        public static void ClearCache()
        {
            System.Web.HttpContext.Current.Cache.Remove(sKey);
        }
    }
}
